#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;


vector<string> split(const string& str, const string& delim) {  
	vector<string> res;  
	if("" == str) return res;  
	//先将要切割的字符串从string类型转换为char*类型  
	char * strs = new char[str.length() + 1];
	strcpy(strs, str.c_str());   
 
	char * d = new char[delim.length() + 1];  
	strcpy(d, delim.c_str());  
 
	char *p = strtok(strs, d);  
	while(p) {  
		string s = p; //分割得到的字符串转换为string类型  
		res.push_back(s); //存入结果数组  
		p = strtok(NULL, d);  
	}  
 
	return res;  
}

void output(set<string> s)
{
    if(s.empty()) cout<<"{}"<<endl;
    for(auto i : s) {
        if( i == *s.begin()) cout<<"{";
        if( i != *s.rbegin()) cout <<i<< ",";
        else cout<<i <<"}"<<endl;
    }
}

int main()
{
    // 读入集合并分隔元素存入vector
    string str1, str2;
    cin>>str1>>str2;
    vector<string> set1 = split(str1, "{,}");
    vector<string> set2 = split(str2, "{,}");
    set<string> set3(set1.begin(),set1.end());
    set<string> set4(set2.begin(),set2.end());

    set<string> set5;    
    set_union(set3.begin(), set3.end(), set4.begin(), set4.end(), inserter(set5, set5.begin()));
    output(set5);


    set5.clear();
    set_intersection(set3.begin(), set3.end(), set4.begin(), set4.end(), inserter(set5, set5.begin()));
    output(set5);

    set5.clear();
    set_difference(set3.begin(), set3.end(), set4.begin(), set4.end(), inserter(set5, set5.begin()));
    output(set5);
    
    set5.clear();
    set_symmetric_difference(set3.begin(), set3.end(), set4.begin(), set4.end(), inserter(set5, set5.begin()));
    output(set5);

    return 0;
}
